<template>
    <div>
        <el-dialog title="查看" class="noselect" v-dialogdrag=" { target:'.el-dialog__header',container:'.el-dialog',border:'.el-dialog__wrapper'}" :close-on-click-modal="false" :visible.sync="showDialog" :before-close="handleClose">
            <div style="margin: 20px;"></div>
          <el-table
            :data="tableData"
            stripe
             border
            style="width: 100%">
            <el-table-column
              prop="thisTime"
              label="下发时间"
              >
            </el-table-column>
            <el-table-column
              prop="state"
              label="状态"
              >
              <template  slot-scope="scope">
                <span v-if="scope.row.state">{{scope.row.state.text}}</span>
              </template>
            </el-table-column>
          </el-table>
          <div class="foot-bar-button">
            <!--<el-button type="primary" @click="submitForm('modelForm')" size="medium">提交</el-button>-->
            <el-button @click="resetForm('modelForm')" type="primary" size="medium">取消</el-button>
          </div>
        </el-dialog>
    </div>
</template>
<script>
    //注意路径
    export default{
        props: ['isShow','id'],  //参数
        data(){
            return {
                modelForm: {
                },
              tableData: [{
                date: '2016-05-02',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1518 弄'
              }, {
                date: '2016-05-04',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1517 弄'
              }, {
                date: '2016-05-01',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1519 弄'
              }, {
                date: '2016-05-03',
                name: '王小虎',
                address: '上海市普陀区金沙江路 1516 弄'
              }],
                 showDialog:false,
                 activityId:"",
                 isSave:true,
            };
        },
        watch:{
            isShow:function(newValue,oldValue){
                this.showDialog=newValue;
                if(newValue){
                    if(this.id!=''){
                        this.activityId=this.id;
                        this.isSave=false;
                        this.$axios.get("branchstores/syncStocks/showRecord?id="+this.activityId).then(data=>{
                            this.tableData=data.content;
                       });
                    }
                }
            }
        },
        created(){
            window.this = this;
        },
        methods: {
            greet(){

            },
            goBack() {
                this.router.go(-1);
            },
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        if(this.isSave){
                            this.$axios.post("branchstores/branchWarehouses/create",this.modelForm).then(data=>{
                                    if(data.status==200){
                                    this.$message({
                                        message:data.message,
                                        type: 'success'
                                    });
                                    this.$emit('addSuccess');
                                }else{
                                    this.$message.error(data.message);
                                }

                            })

                        }else{
                            this.modelForm._method="PUT";
                            this.$axios.put("branchstores/branchWarehouses/"+this.activityId+"/update",this.modelForm).then(data=>{
                                if(data.status==200){
                                    this.$message({
                                        message:data.message,
                                        type: 'success'
                                    });
                                    this.$emit('addSuccess');
                                }else{
                                    this.$message.error(data.message);
                                }
                            })
                        }
                    } else {
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$emit('close');
                this.showDialog=false;
            },
            handleClose(done){
                this.$emit('close');
                done();
            },
            isNum(item,key){
                var r = /^\+?[1-9][0-9]*$/;
                if( ! r.test(item[key])){
                    item[key]="0.00"
                }else{
                    item[key]=item[key]
                }
            },
            isDouble(item,key){
                var isNum=/^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/;
                if( ! isNum.test(item[key])){
                    item[key]="0.00"
                }else{
                    item[key]=item[key]
                }
            }
        }
    }
</script>
<style scoped>

</style>
